package net.wenwuyi.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.wenwuyi.pojo.User;
import net.wenwuyi.service.UserService;
import net.wenwuyi.util.ApplicationSpringContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/user")
public class UserController {
	 private Logger logger = LoggerFactory.getLogger(UserController.class);
/*	 @Autowired 
	 private UserService userService;*/
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(){
		System.err.println("s");
		return "user/add";
	}
	  @RequestMapping(value = "/list", method = RequestMethod.GET)
	  @ResponseBody
	  public Map<String, Object> getUserList() {
	    logger.info("列表");
	    List<User> list = new ArrayList<User>();
	    User um = new User();
	    um.setId(1);
	    list.add(um);
	    Map<String, Object> modelMap = new HashMap<String, Object>(3);
	    modelMap.put("total", "1");
	    modelMap.put("data", list);
	    modelMap.put("success", "true");
	    return modelMap;
	  }
	  @RequestMapping(value = "/add", method = RequestMethod.POST)
	 // @ResponseBody
	  public String addUser(HttpServletRequest req) {
		  System.err.println(req.getParameter("username"));
	        User user = new User();
	        user.setNickname("你ddd好");
	        user.setState(2);
	        UserService userService=(UserService)ApplicationSpringContext.getBean("userService");
	        System.out.println(userService.insertUser(user));
	    logger.info("新增");
	    logger.info("捕获到前台传递过来的Model，名称为：" );
	    Map<String, String> map = new HashMap<String, String>();
	    map.put("success", "true");
	    return "/user/login";
	  }
	  @RequestMapping(value = "/login", method = RequestMethod.GET)
	  public String login(){
		  return "user/login";
	  }
}
